package com.example.unisys.controller;

import com.example.unisys.annotation.Log;
import com.example.unisys.common.Response;
import com.example.unisys.common.STATUS;
import com.example.unisys.entity.Tag;
import com.example.unisys.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;


@RestController
@RequestMapping(value = "/apis/v1/tags", produces = "application/json; charset=utf-8")
public class TagController {

    @Autowired
    TagService tagService;

    @RequestMapping(value = "/getTags", method = {RequestMethod.GET})
    public Response getTags(@RequestParam("limit") int limit, @RequestParam("page") int page) {
        HashMap<String, Object> hs = new HashMap<>();
        int start = (page - 1) * limit;
        hs.put("start", start);
        hs.put("pagesize", limit);
        List<Tag> tags = tagService.getTags(hs);
        return Response.builder().status(STATUS.SUCCESS).total(tagService.getTagsSum()).data(tags).build();
    }
}
